
// 生成路由
const router = require("express").Router();

const { db } = require("../database");
// 权限
const limits = require("../utils/limits")

// 导入用户登录状态检查的中间件
const { useAuthorization } = require("./base")
router.use(useAuthorization);

router
    // 查询权限
    .get("/admin_info", async (req, res) => {
        const id = req.user.id;
        // console.log(1,req.user.id);
        const result = await db.findOne(`select b.name,b.id,b.sex,b.address,b.phone,b.description,b.org,c.rolename from user as a inner join person as b on a.person=b.id inner join role as c on b.duty = c.rolename and a.id = ?`,
            id);
        // console.log(limits[result.rolename]); 
        // console.log(result); 
        res.send({
            code: 200,
            message: "ok",
            result: {
                permissions: limits[result.rolename],
                userId: id,
                name: result.name,
                address: result.address,
                phone: result.phone,
                sex: result.sex,
                description: result.description,
                org: result.org,
            },
        })
    });


const registerRouter = (app) => app.use("/", router);
module.exports = { registerRouter };